package fileDemo;

import java.io.*;
import java.util.Scanner;

public class Demo17 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入源路径：");
        String filename = sc.next();
        File file = new File(filename);
        System.out.println("请输入目标文件路径：");
        String copyName = sc.next();
        if(!file.isFile()){
            System.out.println("源路径不是一个普通的文件！返回！");
            return;
        }
        try(InputStream in = new FileInputStream(file);
            OutputStream ou=new FileOutputStream(copyName) ){
            while(true){
                byte[] b = new byte[1024];
                int len = in.read(b);
                if(len==-1){
                    break;
                }
                for(int i=0;i<len;i++){
                    ou.write(b[i]);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
